let username = $("#username");
let pwd = $("#password");

function contentIsNull() {
  if (username.val() != "") {
    username.next().css("color", "green");
    username.css("borderColor", "green");
  } else {
    username.next().css("color", "red");
    username.css("borderColor", "red");
  }

  if (pwd.val() != "") {
    pwd.next().css("color", "green");
    pwd.css("borderColor", "green");
  } else {
    pwd.next().css("color", "red");
    pwd.css("borderColor", "red");
  }
}

// 登录验证
function checkLogin() {
  if (username.val() !== "" && pwd.val() !== "") {
    $("#realpwd").val(md5(pwd.val()));
    $.ajax({
      url: "http://localhost:8080/test",
      data: { username: username.val(), target: "checkLogin" },
      type: "POST",
      dataType: "json",
      success: function (data) {
        if (data.res === "ok") {
          location.assign("http://127.0.0.1:5500/index.html");
        } else {
          alert("用户名或者密码错误");
        }
      },
      timeout: 3000,
      error: function () {
        alert("网站请求出错，请稍后再试试吧！");
      },
    });
  } else {
    $("#errorTips").css("display", "flex");
    $("#errorTips > p").text("用户名或密码不能为空！");
    return false;
  }
}

function hideError() {
    $("#errorTips").css("display", "none");
    username.val("");
    pwd.val("")
}
